#include <iostream>

using std::cout;
using std::endl;


class Grandpa
{
public:
    Grandpa()
    {   cout << "Grandpa()" << endl;    }

    ~Grandpa()
    {   cout << "~Grandpa()" << endl;   }
    virtual void func1() {  cout << "Grandpa::func1()" << endl;}
    virtual void func2() {  cout << "Grandpa::func2()" << endl;}
};

class Parent
: public Grandpa
{
public:
    Parent()
    {   
        cout << "Parent()" << endl;    
        func1();//在构造函数中调用虚函数
    }
    //virtual void func1() {  cout << "Parent::func1()" << endl;}
    //virtual void func2() {  cout << "Parent::func2()" << endl;}

    ~Parent()
    {   
        cout << "~Parent()" << endl;   
        func2();//在析构函数中调用虚函数
    }
};

class Son
: public Parent
{
public:
    Son() { cout << "Son()" << endl;    }
    ~Son() {    cout << "~Son()" << endl;   }

    virtual void func1() {  cout << "Son::func1()" << endl;}
    virtual void func2() {  cout << "Son::func2()" << endl;}
};


int main()
{
    Son son;

    //Parent parent;

    return 0;
}

